import json

lst = [
    { "name": "jack", "age": 20, "score": 99},
    { "name": "anne", "age": 21, "score": 69},
    { "name": "amy", "age": 22, "score": 89},
]
# 编码
s = json.dumps(lst, indent=4)
print(s, type(s))

# 解码
lst2 = json.loads(s)
print(type(lst2), lst2)

# 写入到文件
with open('demo.json', 'w', encoding='utf-8') as f:
    json.dump(lst, f, ensure_ascii=False, indent=4)

# 读取
with open('demo.json', 'r', encoding='utf-8') as f:
    lst3=json.load(f)
    print(lst3)